/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.disparity;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.Map;
import org.apache.commons.lang3.ArrayUtils;

/**
 *
 * @author aboulton
 */
public class PatchingEngine {

    public static void writeByteArrayToFile(File file, Map<Integer, Byte[]> diffs) throws FileNotFoundException, IOException {
        try (RandomAccessFile raf = new RandomAccessFile(file, "rw")) {
            for (Integer offset : diffs.keySet()) {
             //   System.out.println("[*] Writing to offset: " + offset);
                byte[] finalData = ArrayUtils.toPrimitive(diffs.get(offset));
                
           //     System.out.println("[*] Data size: " + finalData.length);
                
                raf.seek(offset);
       //         System.out.println(ArrayUtils.toString(finalData));
                raf.write(finalData);
                
            }
            
            raf.close();
        }
    }
}
